package com.googlecode.dgwt.client.dijit.theme.impl;

import com.google.gwt.core.client.GWT;
import com.googlecode.dgwt.client.dijit.Dijit;
import com.googlecode.dgwt.client.dijit.theme.CSS;
import com.googlecode.dgwt.client.dijit.theme.Theme;


/**
 * This class is used as an internal feature. <br/>
 * Use {@link Theme} as super class when coding a theme.
 * 
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class StyleSheetTheme {

    protected StyleSheetTheme(){
    }

    final StyleSheetInjectionEngine styleSheetEngine = GWT.create(StyleSheetInjectionEngine.class);

    
    /**
     * Event that occurs when this Theme is set using {@link Dijit#setTheme(Theme)}
     * @see com.googlecode.dgwt.client.dijit.Dijit#setTheme(Theme)
     */
    public void onLoad() {
        getStyleSheetEngine().attach();
    }
    
    
    /**
     * Event that occurs when this Theme is replaced by another
     * @see com.googlecode.dgwt.client.dijit.Dijit#setTheme(Theme)
     */
    public void onUnload() {
        getStyleSheetEngine().detach();
    }

    
    /**
     * Creates an user defined CSS declaration.
     * It should be published to the HTML document
     * using {@link CSS#importDeclaration()}
     * 
     * @return CSS
     */
    public CSS createStyleSheet(){
        return getStyleSheetEngine().create();
    }


    /**
     * Creates an user defined CSS declaration.
     * It should be published to the HTML document
     * using {@link CSS#importDeclaration()}
     *  
     * @param cssText CSS text
     * @return CSS
     */
    public CSS createStyleSheet(String cssText){
        CSS css = getStyleSheetEngine().create();
        css.addDeclaration(cssText);
        return css;
    }


    /**
     * Sets the Theme default direction for elements
     * 
     * @param ltr True if is Left-To-Right direction
     */
    public void setLTR(boolean ltr) {
        getStyleSheetEngine().setLtr(ltr);
    }


    /**
     * Sets the Theme default direction for elements
     * to be retreive from the HTML document.
     * 
     * This is the default behavior.
     */
    public void setLTRDefault() {
        getStyleSheetEngine().setLtr(null);
    }


    /**
     * Gets the Theme default direction for elements
     * 
     * @return True if is Left-To-Right direction
     */
    public boolean isLtr() {
        return getStyleSheetEngine().isLtr();
    }


    protected StyleSheetInjectionEngine getStyleSheetEngine() {
        return styleSheetEngine;
    }


    protected String getProperty(String name) {
        return null;
    }

}
